package priv.tuyou.system.tag;

import java.util.List;

import javax.servlet.jsp.JspException;

import priv.tuyou.constants.WebContext;
import priv.tuyou.system.dao.IArticleDao;
import priv.tuyou.system.po.Advert;
import priv.tuyou.system.po.Article;
import priv.tuyou.tag.BaseTag;

/**
 * 文章标签
 * @author：涂有
 * @date 2017年1月2日 下午11:07:31
 */
public class ArticleTag extends BaseTag{

	private static final long serialVersionUID = -7118316888626049926L;
	protected IArticleDao articleDao = WebContext.getBean(IArticleDao.class);
	
	@Override
	public int doStartTag() throws JspException {
		
		if("getOne".equalsIgnoreCase(type) && value != null){
			
			Article article = dao.get(Article.class, value);
			pageContext.setAttribute(var, article);
		}else if("queryAll".equalsIgnoreCase(type)){//查询全部
			
			List<Article> list = dao.queryAll(Article.class);
			pageContext.setAttribute(var, list);
		}else if("queryRecommend".equalsIgnoreCase(type)){ //查询推荐的
			
			List<Article> list = articleDao.queryRecommend(3);
			pageContext.setAttribute(var, list);
		}else if("queryNewest".equalsIgnoreCase(type)){ //查询最新发布的
			
			List<Article> list = articleDao.queryNewest(5);
			pageContext.setAttribute(var, list);
		}else if("totalCount".equalsIgnoreCase(type)){ //总日志篇数
			
			long count = dao.count(Article.class);
			count += dao.count(Advert.class);
			pageContext.setAttribute(var, count);
		}
		return super.doStartTag();
	}
}
